﻿using System.Collections.Generic;
using System.Text.RegularExpressions;
/// <summary>
/// Regex
/// </summary>
namespace IFramework
{
    public static partial class StringExtension
    {
        public static bool IsMail(this string self)
        {
            if (string.IsNullOrEmpty(self)) return false;
            return Regex.IsMatch(self, @"^\s*([A-Za-z0-9_-]+(\.\w+)*@(\w+\.)+\w{2,5})s*$");
        }
        public static bool IsCellPhoneNumber(this string self)
        {
            if (string.IsNullOrEmpty(self)) return false;
            return Regex.IsMatch(self, @"^[1]+[3,5]+\d{9}");
        }
        public static bool IsAge(this string self)
        {
            if (string.IsNullOrEmpty(self)) return false;
            return Regex.IsMatch(self, @"^\d{1,2}$");
        }
        public static bool IsPassWord(this string self)
        {
            if (string.IsNullOrEmpty(self)) return false;
            return new Regex(@"^[a-zA-Z]\w{5,15}$").IsMatch(self);
        }
        public static bool HasChinese(this string self)
        {
            if (string.IsNullOrEmpty(self)) return false;
            return Regex.IsMatch(self, @"[\u4e00-\u9fa5]");
        }
        public static bool IsUrl(this string self)
        {
            if (string.IsNullOrEmpty(self)) return false;
            return Regex.IsMatch(self, @"[a-zA-z]+://[^\s]*");
        }
        public static bool IsIPv4(this string self)
        {
            if (string.IsNullOrEmpty(self)) return false;
            return Regex.IsMatch(self, @"((25[0 - 5] | 2[0 - 4]\d | ((1\d{ 2})| ([1 - 9] ?\d)))\.){ 3} (25[0 - 5] | 2[0 - 4]\d | ((1\d{ 2})| ([1 - 9] ?\d)))");
        }
    }
}
